<?php

declare (strict_types=1);

namespace App\Model;

use Swoole\Exception;

/**
 * @property int $id
 * @property int $uid
 * @property string $ip
 * @property int $login_time
 * @property string $login_account
 * @property int $platform
 * @property string $params
 */
class LoginLog extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'login_log';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['id', 'uid', 'ip', 'login_time', 'login_account', 'platform', 'params'];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'uid' => 'integer', 'login_time' => 'integer', 'platform' => 'integer'];


    public static function addLoginLog($uid, $account, $platform,$type =1)
    {

        $insertData = [
            'uid' => $uid,
            'login_account' => $account,
            'platform' => $platform,
            'login_time' => time(),
            'ip' => get_real_ip(),
            'type' => $type,
        ];
        try {
            self::insert($insertData);
        } catch (Exception $e) {

            recordExceptionLog('记录登录日志失败', $e->getMessage());
        }

        return true;

    }


}
